﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using gfLibrary;
using System.Drawing;
using IYAKASAPortal.Services;
using System.Data;
using System.Xml.Linq;
using System.IO;
using System.Xml;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using DBUtility;
using System.Configuration;
using System.Reflection;
using UtilityHelper;
using gfVehicleLibraryAJ;
using ConvertInfo;
using Fleck;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace IYAKASAPortal.Login
{
    public partial class LoginAJMotor : System.Web.UI.Page
    {
        private UserInfo userInfo { get; set; }
        private static List<ListItem> lstItems { get; set; }
        private Flecks m_fleck;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
            {
                string userName = Session["UserName"].ToString();
                userInfo = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName);
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }

            if (!IsPostBack)
            {
                BindData();

                if (Request["LineNum"] != null && Request["LineNum"].ToString() != "")
                {
                    lblLineNum.Text = "安检" + Request["LineNum"].ToString() + "号线登录";
                }
                else
                {
                    lblLineNum.Text = "安检登录";
                }

                m_fleck = Flecks.GetInstance();

            }
        }
        //HNK 12/13/2017 PEIKING
        private void BindData()
        {
            lstItems = new List<ListItem>();
            CONST_DEFINE_BLL bll = new CONST_DEFINE_BLL();
            CONST_DEFINE_WEB_CATEGORY_BLL bll_web = new CONST_DEFINE_WEB_CATEGORY_BLL();
            CONST_DEFINE_WEB_CATEGORY m_web = bll_web.GetModel(8);
            this.txtHPHMStart.Text = m_web.CategoryName;

            var def = bll.GetModelList("CON_CHNAME='JYLB' and CON_VTYPE='2' order by CON_ORDER asc");
            ListItem item;
            foreach (var v in def) {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpTestType.Items.Add(item);
            }
            //车辆种类
            var clzl = bll.GetModelList("CON_CHNAME='CLZL' AND CON_CODE LIKE 'M%' order by CON_ORDER asc");
            foreach (var v in clzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpCLZL.Items.Add(item);
            }

            //发动机冲程
            var fdjcc = bll.GetModelList("CON_CHNAME='FDJCC' and CON_VTYPE='1' order by CON_ORDER asc");
            foreach (var v in fdjcc)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpFDJCC.Items.Add(item);
            }

            ListItem fdjccItem = drpFDJCC.Items.FindByValue("4");
            if (fdjccItem != null)
            {
                drpFDJCC.SelectedValue = fdjccItem.Value;
            }


            //号牌种类
            var hpzl = bll.GetModelList("CON_CHNAME='HPZL' and CON_VTYPE='1' order by CON_ORDER asc");
            foreach (var v in hpzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpHPZL.Items.Add(item);
            }
            //普遍为二三轮摩托车 
            ListItem hpzlItem = drpHPZL.Items.FindByValue("07");
            if (hpzlItem != null)
            {
                drpHPZL.SelectedValue = hpzlItem.Value;
            }
            //使用性质
            var syxz = bll.GetModelList("CON_CHNAME='SYXZ' order by CON_ORDER asc");
            foreach (var v in syxz)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpSYXZ.Items.Add(item);
            }
            //燃料类别
            var rllb = bll.GetModelList("CON_CHNAME='RLLB' order by CON_ORDER asc");
            foreach (var v in rllb)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpRLLB.Items.Add(item);
            }
            //前照灯制
            var qzdz = bll.GetModelList("CON_CHNAME='QZDZ' order by CON_ORDER asc");
            foreach (var v in qzdz)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpQZDZ.Items.Add(item);
            }
            drpQZDZ.SelectedValue = "1";

            //检验项目
            var jyxm = bll.GetModelList("CON_CHNAME='JYXM' and CON_JCTYPE like '%10,%' order by CON_ORDER asc");
            foreach (var v in jyxm)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                lstItems.Add(item);
            }

            this.drpSFYJSS.Items.Add(new ListItem { Text = "没有驾驶室", Value = "0" });
            this.drpSFYJSS.Items.Add(new ListItem { Text="有驾驶室", Value = "1" });

            EMPLOYEE_USER_BLL user_bll = new EMPLOYEE_USER_BLL();

            var userYCY = user_bll.GetModelList("LICENSE_NAME like'%02%'");
            drpYCY.Items.Add(new ListItem() { Text = "请选择", Value = "-1" });
            foreach (var v in userYCY)
            {
                item = new ListItem() { Text = v.EMPLOYEE_NAME, Value = v.EMPLOYEE_ID };
                drpYCY.Items.Add(item);
            }

            //绑定模板
            CONST_DEFINE_WEB_BLL cdw_bll = new CONST_DEFINE_WEB_BLL();
            var jyxmmb = cdw_bll.GetModelList("CategoryId='10'");
            foreach (var j in jyxmmb)
            {
                item = new ListItem();
                item.Text = j.Name;
                item.Value = j.ValueOfName;
                rbtnTemplate.Items.Add(item);
            }

          



            //绑定号码开头
            CONST_DEFINE_WEB_CATEGORY_BLL category_bll = new CONST_DEFINE_WEB_CATEGORY_BLL();
            var hphmStart = category_bll.GetModel(8);

            var keyValue = category_bll.GetModel(9);
            hidKeyValue.Value = keyValue.CategoryName;

            //绑定检测项目
            ReBindJCXM();
        }

        protected void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            LoginHelper.CheckAll(chkJYXM, chkAll.Checked);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strMessage;
            bool bLoginInfo = SaveLoginInfo(out strMessage);

            if (bLoginInfo == false)
            {
                #region 日志记录
                LogHelper logHelper = LogHelper.GetSingleLogHelper();

                string strCategory = LogHelper.LogType.Error.ToString();
                LOG_INFO logInfo = new LOG_INFO();
                logInfo.Category = strCategory;
                logInfo.HostName = System.Net.Dns.GetHostName();
                logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                logInfo.LogTime = DateTime.Now;
                logInfo.Log_Infor = "系统错误，错误信息为：" + strMessage;
                logInfo.OpName = userInfo.UserName;
                logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Error);
                logInfo.FunName = "LoginAJ.aspx.cs -> btnSave_Click";

                logHelper.WriteLog(logInfo);
                #endregion

                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, strMessage);
                return;
            }
            else
            {
                string strHPHM = txtHPHMStart.Text.Trim() + txtHPHM.Text.Trim().ToUpper();
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车牌号码【" + strHPHM + "】保存成功！");
            }
        }

        /// <summary>
        /// 保存登录基本信息
        /// </summary>
        /// <returns></returns>
        private bool SaveLoginInfo(out string strMessage)
        {
            bool bRet = false;
            //安检检验登录

            //车辆种类
            string strCLZL = this.drpCLZL.SelectedValue.Trim();
            string strJYLB = drpTestType.SelectedValue.Trim() + ",";
            string strHPHM = txtHPHMStart.Text.Trim().ToUpper() + txtHPHM.Text.Trim().ToUpper();
            string strHPHM_H = txtHPHMStart.Text.Trim().ToUpper();
            string strHPHM_C = txtHPHM.Text.Trim().ToUpper();

            //号牌种类
            string strHPZL = drpHPZL.SelectedValue.Trim();
            string strVIN = txtVIN.Text.Trim().ToUpper();
            if (strJYLB.Contains("02"))
            {
                string strGuid = Guid.NewGuid().ToString();
                strHPHM = string.Format("试{0}", strVIN.Length > 6 ? strVIN.Substring(strVIN.Length - 6) : strGuid.Substring(strGuid.Length - 6).ToUpper());
            }
            string strSYR = txtSYR.Text.Trim();
            string strAddress = txtAddress.Text.Trim();
            //品牌&型号
            string strPP = txtPP.Text.Trim();
            string strXH = txtXH.Text.Trim().ToUpper();
            //发动机号
            string strFDJHM = txtFDJNumber.Text.Trim().ToUpper();
            string strCCRQ = txtCCRQ.Text.Trim();
            string strCSDJRQ = txtCSDJRQ.Text.Trim();
            //核载人数
            string strHZRS = txtHZRS.Text.Trim();
            //总质量&整备质量
            string strZZL = txtZZL.Text.Trim();
            string strZBZL = txtZBZL.Text.Trim();
            //核定总质量
            string strHDZZL = txtHDZZL.Text.Trim();
            //string strZGSJCS = txtZGSJCS.Text.Trim();
            //累计行驶里程
            string strLJXSLC = txtLJXSLC.Text.Trim();
            string strAJLSH = txtAJLSH.Text.Trim();
            //前照灯制&远光是否可调
            string strQZDZ = drpQZDZ.SelectedValue.Trim();
            //摩托车是否带驾驶室
            string strSFDJSS = drpSFYJSS.SelectedValue.Trim();
            //VIN
            if (string.IsNullOrEmpty(strVIN) == false)
            {
                txtVIN.BackColor = Color.White;
            }

            //所有人
            if (string.IsNullOrEmpty(strSYR) == false)
            {
                txtSYR.BackColor = Color.White;
            }

            //住址
            if (string.IsNullOrEmpty(strAddress) == false)
            {
                txtAddress.BackColor = Color.White;
            }

            //品牌
            if (string.IsNullOrEmpty(strPP) == false)
            {
                txtPP.BackColor = Color.White;
            }

            //型号
            if (string.IsNullOrEmpty(strXH) == false)
            {
                txtXH.BackColor = Color.White;
            }

            //发动机/电动机号码
            if (string.IsNullOrEmpty(strFDJHM) == false)
            {
                txtFDJNumber.BackColor = Color.White;
            }

            //出厂日期
            if (!string.IsNullOrEmpty(strCCRQ))
            {
                if (gfValidate.Is_DateTime(strCCRQ) == false)
                {
                    strMessage = "出厂日期不是有效的日期格式！";
                    txtCCRQ.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtCCRQ.BackColor = Color.White;
                }
            }

            //初始登记日期
            if (!string.IsNullOrEmpty(strCSDJRQ))
            {
                if (gfValidate.Is_DateTime(strCSDJRQ) == false)
                {
                    strMessage = "初始登记日期不是日期格式！";
                    txtCSDJRQ.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtCSDJRQ.BackColor = Color.White;
                }
            }

            //核载人数
            if (string.IsNullOrEmpty(strHZRS) == false)
            {
                if (gfValidate.Is_Integer(strHZRS) == false)
                {
                    strMessage = "核载人数不是数字格式！";
                    txtHZRS.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtHZRS.BackColor = Color.White;
                }

            }

            //总质量
            if (string.IsNullOrEmpty(strZZL) == false)
            {
                if (!gfValidate.Is_Integer(strZZL))
                {
                    strMessage = "总质量只能为整数！";
                    txtZZL.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtZZL.BackColor = Color.White;
                }
            }

            //整备质量
            if (string.IsNullOrEmpty(strZBZL) == false)
            {
                if (!gfValidate.Is_Integer(strZBZL))
                {
                    strMessage = "整备质量只能为整数！";
                    txtZBZL.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtZBZL.BackColor = Color.White;
                }
            }

            //核定载质量
            if (!string.IsNullOrEmpty(strHDZZL) && !gfValidate.Is_Integer(strHDZZL))
            {
                strMessage = "核定载质量只能为整数！";
                txtHDZZL.BackColor = Color.Yellow;
                return bRet;
            }
            else
            {
                txtHDZZL.BackColor = Color.White;
            }


            //累计行驶里程
            if (string.IsNullOrEmpty(strLJXSLC) == false)
            {
                if (!gfLibrary.gfValidate.Is_Float(strLJXSLC))
                {
                    strMessage = "累计行驶里程不是有效的数字格式！";
                    txtLJXSLC.BackColor = Color.Yellow;
                    return bRet;
                }
                else
                {
                    txtLJXSLC.BackColor = Color.White;
                }
            }

          

            string strJYXM = "";
            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                if (chkJYXM.Items[i].Selected)
                {
                    strJYXM += chkJYXM.Items[i].Value + ",";
                }
            }

            //string strSFSQCLC = chkQCLC.Checked ? "1" : "0";

            string strVEHICLEID = strHPZL + strHPHM;

            LOGIN_VEHICLE_INFO info = new LOGIN_VEHICLE_INFO();
            info.VEHICLEID = strVEHICLEID;
            info.HPHM = strHPHM;
            info.AJLSH = strAJLSH;
            info.CLZL = drpCLZL.SelectedItem.Text;
            info.CLZLDH = drpCLZL.SelectedItem.Value;
            info.HPZL = drpHPZL.SelectedItem.Text;
            info.HPZLDH = strHPZL;
            info.VIN = strVIN;
            info.JYLB = drpTestType.SelectedItem.Text;
            info.JYLBDH = strJYLB;
            info.FDJH = strFDJHM;
            info.PP = strPP;
            info.XH = strXH;
            info.PPXH = strPP + strXH;
            info.QZDZ = drpQZDZ.SelectedItem.Text;
            info.QZDZDH = drpQZDZ.SelectedItem.Value;
            info.RLLB = drpRLLB.SelectedItem.Text;
            info.RLLBDH = drpRLLB.SelectedItem.Value;
            info.CCDJRQ = strCSDJRQ;
            info.CCRQ = strCSDJRQ;
            info.ZBZL = strZBZL;
            info.ZZL = strZZL;
            info.CYS = strHZRS;
    
            info.SYR = strSYR;
            info.LXDZ = strAddress;
            info.SYXZ = drpSYXZ.SelectedItem.Text;
            info.SYXZDH = drpSYXZ.SelectedItem.Value;
            info.HDZH = strHDZZL;
            info.JYXM_LW = strJYXM;
            info.JYXM = strJYXM;

            info.DLY = txtDLY.Text.Trim();
            info.CCRQ = strCCRQ;
            info.LJXSLC = strLJXSLC;
            info.MTCSFDJSS = strSFDJSS;
            info.YCY = drpYCY.SelectedItem.Text;
            info.FDJCC = drpFDJCC.SelectedItem.Value;

            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();

            if (string.IsNullOrEmpty(userInfo.UserName))
            {
                strMessage = "当前没有授权,请退出系统重新登录！";
                return bRet;
            }

            bool bOnGoing = LoginHelper.GetVehicleStatus(strVEHICLEID);
            if (bOnGoing)
            {
                strMessage = "车辆【" + strVEHICLEID + "】正在检测，不能保存当前信息！";
                return bRet;
            }

            var vInfo = LoginHelper.GetLoginInfo(strHPHM, strHPZL);

            if (vInfo == null)
            {
                if (bll.Insert(info) == true)
                {
                    strMessage = "";
                    hidID.Value = LoginHelper.GetLoginInfo(strHPHM, strHPZL).ID.ToString();
                    LoginHelper.SavePPXHAndFDJXH(info);
                    #region 日志记录
                    LogHelper logHelper = LogHelper.GetSingleLogHelper();

                    string strCategory = LogHelper.LogType.Normal.ToString();
                    LOG_INFO logInfo = new LOG_INFO();
                    logInfo.Category = strCategory;
                    logInfo.JCLSH = strHPHM;
                    logInfo.HostName = System.Net.Dns.GetHostName();
                    logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                    logInfo.LogTime = DateTime.Now;
                    logInfo.Log_Infor = strHPHM + "添加成功";
                    logInfo.OpName = userInfo.UserName;
                    logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Normal);
                    logInfo.FunName = "LoginAJ.aspx.cs -> SaveLoginInfo";

                    logHelper.WriteLog(logInfo);
                    #endregion
                    return true;
                }
                else
                {
                    strMessage = "车牌号码【" + strHPHM + "】保存失败！";
                    return bRet;
                }
            }
            else
            {
                if (bll.Update(info, vInfo.ID) == true)
                {
                    strMessage = "";
                    hidID.Value = vInfo.ID.ToString();
                    LoginHelper.SavePPXHAndFDJXH(info);
                    #region 日志记录
                    LogHelper logHelper = LogHelper.GetSingleLogHelper();

                    string strCategory = LogHelper.LogType.Normal.ToString();
                    LOG_INFO logInfo = new LOG_INFO();
                    logInfo.Category = strCategory;
                    logInfo.JCLSH = vInfo.HPHM;
                    logInfo.HostName = System.Net.Dns.GetHostName();
                    logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                    logInfo.LogTime = DateTime.Now;
                    logInfo.Log_Infor = vInfo.HPHM + "更新成功";
                    logInfo.OpName = userInfo.UserName;
                    logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Normal);
                    logInfo.FunName = "LoginAJ.aspx.cs -> SaveLoginInfo";

                    logHelper.WriteLog(logInfo);
                    #endregion
                    return true;
                }
                else
                {
                    strMessage = "车牌号码【" + strHPHM + "】更新失败！";
                    return bRet;
                }
            }
        }

        private void ResetAll()
        {
            //drpZZS.SelectedValue = "2";
            //drpZZS_SelectedIndexChanged(null, null);

            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZL.ID, ""));
            lstControls.Add(drpHPZL);

          

            lstCtl.Add(new LoginHelper.ControlNames(drpQZDZ.ID, ""));
            lstControls.Add(drpQZDZ);

            //lstCtl.Add(new LoginHelper.ControlNames(drpQDXS.ID, ""));
            //lstControls.Add(drpQDXS);

            lstCtl.Add(new LoginHelper.ControlNames(drpRLLB.ID, ""));
            lstControls.Add(drpRLLB);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQ.ID, ""));
            lstControls.Add(txtCCRQ);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZ.ID, ""));
            lstControls.Add(drpSYXZ);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZL.ID, ""));
            lstControls.Add(drpCLZL);

            lstCtl.Add(new LoginHelper.ControlNames(drpYCY.ID, ""));
            lstControls.Add(drpYCY);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddress.ID, ""));
            lstControls.Add(txtAddress);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSDJRQ.ID, ""));
            lstControls.Add(txtCSDJRQ);

            lstCtl.Add(new LoginHelper.ControlNames(txtFDJNumber.ID, ""));
            lstControls.Add(txtFDJNumber);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZL.ID, ""));
            lstControls.Add(txtHDZZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtHZRS.ID, ""));
            lstControls.Add(txtHZRS);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHM.ID, ""));
            lstControls.Add(txtHPHM);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYR.ID, ""));
            lstControls.Add(txtSYR);

            lstCtl.Add(new LoginHelper.ControlNames(txtPP.ID, ""));
            lstControls.Add(txtPP);

            lstCtl.Add(new LoginHelper.ControlNames(txtVIN.ID, ""));
            lstControls.Add(txtVIN);

            lstCtl.Add(new LoginHelper.ControlNames(txtXH.ID, ""));
            lstControls.Add(txtXH);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZL.ID, ""));
            lstControls.Add(txtZBZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZL.ID, ""));
            lstControls.Add(txtZZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtAJLSH.ID, ""));
            lstControls.Add(txtAJLSH);

            lstCtl.Add(new LoginHelper.ControlNames(txtLJXSLC.ID, ""));
            lstControls.Add(txtLJXSLC);

            LoginHelper.ResetAllControls(lstCtl, lstControls);

         //   drpZZS_SelectedIndexChanged(null, null);

            lstItems.All(x => x.Selected = false);

            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                chkJYXM.Items[i].Selected = false;
            }
            btnSave.Enabled = true;
            btnSave.CssClass = "btnSaveEnabled";
            LoginHelper.ResetAllValidate(GetType(), this);

            ListItem hpzlItem = drpHPZL.Items.FindByValue("07");
            if (hpzlItem != null)
            {
                drpHPZL.SelectedValue = hpzlItem.Value;
            }
        }

        /// <summary>
        /// 获取服务器通讯的IP地址和端口
        /// </summary>
        /// <returns></returns>
        public string GetIPAndPort()
        {
            string strIP = string.Empty;
            CONST_DEFINE_WEB_BLL bll = new CONST_DEFINE_WEB_BLL();
            var Infos = bll.GetModelList(" Name='DBAddress'");

            //Infos[0].ValueOfName = "127.0.0.1";
            //Infos[0].Code = "8184";

            if (Infos.Length > 0)
            {
                strIP = string.Format("ws://{0}:{1}", Infos[0].ValueOfName, Infos[0].Code);
            }
            return strIP;

        }

        private void LoadData(LOGIN_VEHICLE_INFO login_Info , bool sflw)
        {
            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpTestType.ID, "JYLBDH"));
            lstControls.Add(drpTestType);

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZL.ID, "HPZLDH"));
            lstControls.Add(drpHPZL);

            lstCtl.Add(new LoginHelper.ControlNames(drpQZDZ.ID, "QZDZDH"));
            lstControls.Add(drpQZDZ);
      
            lstCtl.Add(new LoginHelper.ControlNames(drpRLLB.ID, "RLLBDH"));
            lstControls.Add(drpRLLB);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQ.ID, "CCRQ"));
            lstControls.Add(txtCCRQ);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZ.ID, "SYXZDH"));
            lstControls.Add(drpSYXZ);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZL.ID, "CLZLDH"));
            lstControls.Add(drpCLZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddress.ID, "LXDZ"));
            lstControls.Add(txtAddress);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSDJRQ.ID, "CCDJRQ"));
            lstControls.Add(txtCSDJRQ);

            lstCtl.Add(new LoginHelper.ControlNames(txtFDJNumber.ID, "FDJH"));
            lstControls.Add(txtFDJNumber);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZL.ID, "HDZH"));
            lstControls.Add(txtHDZZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtHZRS.ID, "CYS"));
            lstControls.Add(txtHZRS);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHM.ID, "HPHM"));
            lstControls.Add(txtHPHM);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMStart.ID, "HPHM"));
            lstControls.Add(txtHPHMStart);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYR.ID, "SYR"));
            lstControls.Add(txtSYR);

            lstCtl.Add(new LoginHelper.ControlNames(txtPP.ID, "PP"));
            lstControls.Add(txtPP);

            lstCtl.Add(new LoginHelper.ControlNames(txtVIN.ID, "VIN"));
            lstControls.Add(txtVIN);

            lstCtl.Add(new LoginHelper.ControlNames(txtXH.ID, "XH"));
            lstControls.Add(txtXH);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZL.ID, "ZBZL"));
            lstControls.Add(txtZBZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtLJXSLC.ID, "LJXSLC"));
            lstControls.Add(txtLJXSLC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZL.ID, "ZZL"));
            lstControls.Add(txtZZL);

            lstCtl.Add(new LoginHelper.ControlNames(txtAJLSH.ID, "AJLSH"));
            lstControls.Add(txtAJLSH);

            lstCtl.Add(new LoginHelper.ControlNames(txtDLY.ID, "DLY"));
            lstControls.Add(txtDLY);
       
            LoginHelper.LoadData(login_Info, lstCtl, lstControls);

            drpQZDZ_SelectedIndexChanged(null, null);

            string strJYXM = "";
            Networking netWorking = Networking.Instance;

            if (netWorking.bSFLW == false)
            {
                LoginHelper.ConfirmJCXS(login_Info, "A", rbtnTest, lblJCCS, out strJYXM);

                if (rbtnTest.SelectedValue == "0")
                {
                    strJYXM = login_Info.JYXM;
                }
            }
            else
            {
                strJYXM = login_Info.JYXM;
            }

           

            strJYXM = LoginHelper.GetMotoLocalJYXM(strJYXM);

            strJYXM = LoginHelper.GetMotoJYXMFromNet(strJYXM);
       
            LoginHelper.BindJYXM(strJYXM, chkJYXM, lstItems,sflw);

            btnSave.Enabled = true;
            btnSave.CssClass = "btnSaveEnabled";
        
            LoginHelper.ResetAllValidate(GetType(), this);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strHPHMStart = txtHPHMStart.Text;
            string strHPHM = txtHPHMStart.Text.Trim().ToUpper() + txtHPHM.Text.Trim().ToUpper();
            string strVIN = txtVIN.Text.Trim().ToUpper();

            string strHPZL = drpHPZL.SelectedValue;

            if (string.IsNullOrEmpty(strHPHM) && string.IsNullOrEmpty(strVIN))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请输入号牌号码或者VIN进行查询！");
                return;
            }

            if (chkSFLW.Checked)
            {
                try
                {
                    Networking netWorking = Networking.Instance;

                    if (netWorking.bSFLW)
                    {
                        try
                        {
                            Vehicle_18J52_Para m_18J52_Para = new Vehicle_18J52_Para();
                            m_18J52_Para.clsbdh = strVIN;
                            m_18J52_Para.hphm = strHPHM;
                            m_18J52_Para.hpzl = strHPZL;
                            m_18J52_Para.jkid = "18J52";
                            m_18J52_Para.jkxlh = netWorking.jkxlh;
                            m_18J52_Para.xtlb = netWorking.xtlb;
                            m_18J52_Para.dly = userInfo.UserName;
                            m_18J52_Para.dlysfzh = userInfo.UserID;

                            AJ_ModelToXML m_ModelToXML = new AJ_ModelToXML();
                            string strXML = m_ModelToXML.ModelToXml("18J52", m_18J52_Para);

                            IYASAKANetService.VehicleForIYASAKAService_AJSoapClient client = new IYASAKANetService.VehicleForIYASAKAService_AJSoapClient();
                            string strRetXML= client.queryObjectOut(netWorking.xtlb, netWorking.jkxlh, "18J52", strXML);

                            AJ_XMLToModel m_XMLToModel = new AJ_XMLToModel();
                            Vehicle_18J52_Result m_18J52_Result = (Vehicle_18J52_Result)m_XMLToModel.Result_XmlToModel("18J52", strRetXML);

                            if (m_18J52_Result.code == "0")
                            {
                                #region 日志记录
                                LogHelper logHelper = LogHelper.GetSingleLogHelper();

                                string strCategory = LogHelper.LogType.NetFail.ToString();
                                LOG_INFO logInfo = new LOG_INFO();
                                logInfo.Category = strCategory;
                                logInfo.HostName = System.Net.Dns.GetHostName();
                                logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                                logInfo.FS_Infor = strXML;
                                logInfo.JS_Infor = strRetXML;
                                logInfo.LogTime = DateTime.Now;
                                logInfo.Log_Infor = "联网查询失败：" + m_18J52_Result.message;
                                logInfo.OpName = userInfo.UserName;
                                logInfo.Name = logHelper.GetLogName(LogHelper.LogType.NetFail);
                                logInfo.FunName = "LoginAJ.aspx.cs -> btnSearch_Click";

                                logHelper.WriteLog(logInfo);
                                #endregion

                                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, m_18J52_Result.message);
                            }
                            else
                            {
                                LOGIN_VEHICLE_INFO info = new LOGIN_VEHICLE_INFO();
                                info.HPHM = m_18J52_Result.hphm.ValidateNull();
                                info.HPZLDH = m_18J52_Result.hpzl.ValidateNull();
                                info.VIN = m_18J52_Result.clsbdh.ValidateNull();
                                info.CLZLDH = m_18J52_Result.cllx.ValidateNull();
                                info.JYLBDH = m_18J52_Result.jylb.ValidateNull();
                                info.SYR = m_18J52_Result.syr.ValidateNull();
                                //info.LXDZ = m_18J52_Result.lx
                                info.SYXZDH = m_18J52_Result.syxz.ValidateNull();
                                info.PP = m_18J52_Result.clpp1.ValidateNull();
                                info.XH = m_18J52_Result.clxh.ValidateNull();
                                info.FDJH = m_18J52_Result.fdjh.ValidateNull();
                                info.CCDJRQ = m_18J52_Result.ccdjrq.ToString("yyyy-MM-dd");
                                info.CCRQ = m_18J52_Result.ccrq.ToString("yyyy-MM-dd");
                                info.CYS = m_18J52_Result.zkrs.ValidateIntNull();
                                info.ZZL = m_18J52_Result.zzl.ValidateIntNull();
                                info.ZBZL = m_18J52_Result.zbzl.ValidateIntNull();
                                info.HDZH = m_18J52_Result.hdzzl.ValidateIntNull();
                                info.CSC = m_18J52_Result.cwkc.ValidateIntNull();
                                info.CSG = m_18J52_Result.cwkg.ValidateIntNull();
                                info.CSK = m_18J52_Result.cwkk.ValidateIntNull();

                                info.DLY = !string.IsNullOrEmpty(m_18J52_Result.wjy) ? m_18J52_Result.wjy.ToString() : string.Empty;
                                     
                                if (!string.IsNullOrEmpty(m_18J52_Result.sfqszxz))
                                {
                                    info.ZXZLXDH = m_18J52_Result.sfqszxz;
                                }
                                info.QDXSDH = m_18J52_Result.qdxs.ValidateNull();
                                info.ZXZXJXSDH = m_18J52_Result.zxzxjxs.ValidateNull();
                                info.QZDZDH = m_18J52_Result.qzdz.ValidateNull();
                                info.YGGSNFKTDH = m_18J52_Result.ygddtz.ValidateNull();
                                info.ZZS = m_18J52_Result.zs.ValidateIntNull();
                                info.QDZWZ = !string.IsNullOrEmpty(m_18J52_Result.qdzwz) ? m_18J52_Result.qdzwz : "";
                                info.ZCZWZ = m_18J52_Result.zczw.ValidateNull();
                                info.RLLBDH = m_18J52_Result.rlzl.ValidateNull();
                                lblJCCS.Text = m_18J52_Result.jycs.ValidateIntNull();
                                if (m_18J52_Result.jycs == 1)
                                {
                                    rbtnTest.SelectedValue = "0";
                                    info.JYXM = LoginHelper.GetMotoJYXMFromNet(m_18J52_Result.jyxm);
                           
                                }
                                else
                                {
                                    rbtnTest.SelectedValue = "1";
                                    info.JYXM = LoginHelper.GetMotoJYXMFromNet(m_18J52_Result.jyxm);
                                }

                                info.AJLSH = m_18J52_Result.jylsh;
                                info.LJXSLC = m_18J52_Result.lcbds.ValidateNull();

                                if (string.IsNullOrEmpty(m_18J52_Result.rgwjxm) == false)
                                {
                                    hidWGAllJYXM.Value = m_18J52_Result.rgwjxm;
                                }

                                if (m_18J52_Result.wjpd == "1")
                                {
                                    hidWGItems.Value = "-@" + m_18J52_Result.wjy;
                                }
                                else if (m_18J52_Result.wjpd == "0")
                                {
                                    hidWGItems.Value = "";
                                }
                                else
                                {
                                    hidWGItems.Value = m_18J52_Result.xbwjbhgx + "@" + m_18J52_Result.wjy;
                                }

                                if (m_18J52_Result.dtdppd == "1")
                                {
                                    hidDTItems.Value = "-@" + m_18J52_Result.dtdpjyy + "@";
                                }
                                else if (m_18J52_Result.dtdppd == "2")
                                {
                                    hidDTItems.Value = m_18J52_Result.xbdtdpbhgx + "@" + m_18J52_Result.dtdpjyy + "@" + m_18J52_Result.dpdtbhgyy;
                                }
                                else
                                {
                                    hidDTItems.Value = "";
                                }

                                if (info.JYXM.Contains("DC") && m_18J52_Result.dtdppd == "0")
                                {
                                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "该车检验流程不正确！");
                                    btnSend.Enabled = false;
                                    btnSend.CssClass = "btnSendDisabled";
                                }
                                else
                                {
                                    btnSend.Enabled = true;
                                    btnSend.CssClass = "btnSendEnabled";
                                }

                          
                                LoadData(info, true);
                            }
                        }
                        catch (Exception ex)
                        {
                            #region 日志记录
                            LogHelper logHelper = LogHelper.GetSingleLogHelper();

                            string strCategory = LogHelper.LogType.NPFail.ToString();
                            LOG_INFO logInfo = new LOG_INFO();
                            logInfo.Category = strCategory;
                            logInfo.HostName = System.Net.Dns.GetHostName();
                            logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                            logInfo.LogTime = DateTime.Now;
                            logInfo.Log_Infor = "内部联网平台错误，错误信息为：" + ex.Message;
                            logInfo.OpName = userInfo.UserName;
                            logInfo.Name = logHelper.GetLogName(LogHelper.LogType.NPFail);
                            logInfo.FunName = "LoginAJ.aspx.cs -> btnSearch_Click";

                            logHelper.WriteLog(logInfo);
                            #endregion

                            gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "内部联网平台错误：" + ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请设置成联网模式！");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, ex.Message);
                    return;
                }
            }
            else
            {
                btnSend.Enabled = true;
                btnSend.CssClass = "btnSendEnabled";
                LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
                string strJYLB = drpTestType.SelectedValue + ",";
                string strSql = "";
                if (!string.IsNullOrEmpty(strHPHM))
                {
                    strSql = " VEHICLEID='" + drpHPZL.SelectedValue + strHPHM + "'  and HPZLDH='" + strHPZL + "' order by ID desc";
                }
                else if (!string.IsNullOrEmpty(strVIN))
                {
                    strSql = " VIN='" + strVIN + "'  and HPZLDH='" + strHPZL + "' order by ID desc";
                }

                LOGIN_VEHICLE_INFO[] infos = bll.GetModelList(strSql);

                if (infos.Length == 1)
                {
                    LoadData(infos[0],false);
                }
                else if (infos.Length > 1)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果大于1条，显示为最近记录！");
                    LoadData(infos[0],false);
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果为空！");
                    ResetAll();

                    txtHPHMStart.Text = strHPHMStart;
                    txtHPHM.Text = strHPHM.Substring(1);
                    txtVIN.Text = strVIN;
                    drpHPZL.SelectedValue = strHPZL;
                }
            }

            try
            {
                EMPLOYEE_USER entity = IYAKASAPortal.Statistics.StaInfoTools.GetLatestOperatorByLine(5);
                if (entity != null)
                {
                    drpYCY.SelectedValue = entity.EMPLOYEE_ID;
                }
            }
            catch (Exception ex)
            {
 
            }
        }

       
        protected void btnReset_Click(object sender, EventArgs e)
        {
            ResetAll();
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            bool bIsFirstTest_ZC = rbtnTest.SelectedValue == "0" ? true : false;//是否为初检

            if (drpYCY.SelectedValue == "-1")
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择引车员后，再进行发送！");
                return;
            }

            //bool bHasCharge = LoginHelper.HasCharge(hidID.Value, "A", bIsFirstTest_ZC);
            //if (!bHasCharge)
            //{
            //    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前车辆没有收费，请收费后在发送！");
            //    return;
            //}

            string strMessage;
            bool bLoginInfo = SaveLoginInfo(out strMessage);
            if (bLoginInfo == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, strMessage);
                return;
            }

            LoginHelper.ResetAllValidate(GetType(), this);
            
            var dicCheckItems = LoginHelper.CheckAllInputItems(hidID.Value, "", "AMOTO");
            if (dicCheckItems["AMOTO"].Count > 0)
            {
                foreach (var v in dicCheckItems["AMOTO"])
                {
                    TextBox txt = (TextBox)this.FindControl(v);
                    if (txt != null)
                    {
                        txt.BackColor = Color.Yellow;
                    }
                }
                return;
            }
            
            LOGIN_VEHICLE_INFO_BLL info_bll = new LOGIN_VEHICLE_INFO_BLL();
            var info = info_bll.GetModel(Convert.ToInt32(hidID.Value));
            info.YCY = drpYCY.SelectedItem.Text;
            if (string.IsNullOrEmpty(info.JYXM))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择检验项目保存后，在进行发送！");
                return;
            }


          

            bool bIsUpdate_ZC;
            VEHICLE_DISPATCH model_ZC = LoginHelper.GetDispathchByLoginID(hidID.Value, "A", bIsFirstTest_ZC, out bIsUpdate_ZC);
            model_ZC.JCZT_STATUS = 1;   //发送直接上线
            model_ZC.YCY = drpYCY.SelectedItem.Text;
            model_ZC.JCXH = Convert.ToInt32(Request["LineNum"]);
            VEHICLE_DISPATCH_BLL disBll = new VEHICLE_DISPATCH_BLL();

            #region 保存外检的不合格项和引车员
            string strWGItems = hidWGItems.Value;
            string strDTItems = hidDTItems.Value;
            string strWGAllJYXM = hidWGAllJYXM.Value;
            RESULT_CHASISS_MANUAL_BLL manual_bll = new RESULT_CHASISS_MANUAL_BLL();
            RESULT_CHASISS_MANUAL manual = new RESULT_CHASISS_MANUAL();

            if (!string.IsNullOrEmpty(strWGItems))
            {
                LoginHelper.SaveWJDatasFromNet(model_ZC.JCLSH, strWGItems, strWGAllJYXM, strDTItems, true);
            }

            manual.DTDP_PD = string.Empty;
            if (string.IsNullOrEmpty(strDTItems) == false && strDTItems.Contains("@"))
            {
                string[] strDTArr = strDTItems.Split('@');

                if (!string.IsNullOrEmpty(strDTArr[0]))
                {
                    manual.DGJYBHGX = strDTArr[0];
                }
                if (!string.IsNullOrEmpty(strDTArr[1]))
                {
                    manual.DTDPCZY = strDTArr[1];
                }

                if (manual.DGJYBHGX == "-")
                {
                    manual.DTDP_PD = "1";
                    manual.DTDP_MS = "无";
                }
                else
                {
                    string strDTDPBUGX = manual.DGJYBHGX;
                    if (strDTDPBUGX.IndexOf(',') > 0)
                    {
                        var dtItems = strDTDPBUGX.Split(',');
                        foreach (var v in dtItems)
                        {
                            if (string.IsNullOrEmpty(v))
                            {
                                continue;
                            }
                            manual.DTDP_PD = "2";
                            manual.DTDP_MS += LoginHelper.AJGetWJItem(v) + ",";
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(strDTDPBUGX))
                        {
                            manual.DTDP_PD = "2";
                            manual.DTDP_MS = LoginHelper.AJGetWJItem(strDTDPBUGX);
                        }
                    }

                }

                manual.DGJYBHGX += ",";
            }

            if (string.IsNullOrEmpty(strWGItems) == false && strWGItems.Contains("@"))
            {
                manual.JCLSH = model_ZC.JCLSH;
                string[] strItems = strWGItems.Split('@');
                if (!string.IsNullOrEmpty(strItems[0]))
                {
                    manual.RGJYBHGX = strItems[0];
                }
                if (!string.IsNullOrEmpty(strItems[1]))
                {
                    manual.WGJCCZY = strItems[1];
                }

                #region 设置默认值
                manual.WYXRD_PD = "1";
                manual.CLTZCSJC_PD = "1";
                manual.WGJC_PD = "1";
                manual.AQZZJY_PD = "1";
                manual.LWCX_PD = "1";
                #endregion

                string strWYXRD_MS = "";
                string strCLTZCSJC_MS = "";
                string strWGJC_MS = "";
                string strAQZZJY_MS = "";
                if (!string.IsNullOrEmpty(manual.RGJYBHGX))
                {
                    if (manual.RGJYBHGX == "-")
                    {
                        manual.WYXRD_PD = "1";
                        strWYXRD_MS = "无";
                        manual.CLTZCSJC_PD = "1";
                        strCLTZCSJC_MS = "无";
                        manual.WGJC_PD = "1";
                        strWGJC_MS = "无";
                        manual.AQZZJY_PD = "1";
                        strAQZZJY_MS = "无";
                        manual.LWCX_PD = "1";
                        strAQZZJY_MS = "无";
                    }
                    else
                    {
                        string strRGJYBHGX = manual.RGJYBHGX;

                        if (strRGJYBHGX.IndexOf(',') > 0)
                        {
                            var items = strRGJYBHGX.Split(',');
                            foreach (var v in items)
                            {
                                if (string.IsNullOrEmpty(v))
                                {
                                    continue;
                                }
                                int iSub = Convert.ToInt32(v);

                                if (iSub > 0 && iSub < 7)
                                {
                                    manual.WYXRD_PD = "2";
                                    strWYXRD_MS += LoginHelper.AJGetWJItem(v) + ",";
                                }
                                else if (iSub > 6 && iSub < 16)
                                {
                                    manual.CLTZCSJC_PD = "2";
                                    strCLTZCSJC_MS += LoginHelper.AJGetWJItem(v) + ",";
                                }
                                else if (iSub > 15 && iSub < 22)
                                {
                                    manual.WGJC_PD = "2";
                                    strWGJC_MS += LoginHelper.AJGetWJItem(v) + ",";
                                }
                                else if (iSub > 21 && iSub < 42)
                                {
                                    manual.AQZZJY_PD = "2";
                                    strAQZZJY_MS += LoginHelper.AJGetWJItem(v) + ",";
                                }
                                else if (iSub == 80)
                                {
                                    manual.LWCX_PD = "2";
                                    strAQZZJY_MS += LoginHelper.AJGetWJItem(v) + ",";
                                }
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(strRGJYBHGX))
                            {
                                int iSub = Convert.ToInt32(strRGJYBHGX);

                                if (iSub > 0 && iSub < 7)
                                {
                                    manual.WYXRD_PD = "2";
                                    strWYXRD_MS = LoginHelper.AJGetWJItem(strRGJYBHGX);
                                }
                                else if (iSub > 6 && iSub < 16)
                                {
                                    manual.CLTZCSJC_PD = "2";
                                    strCLTZCSJC_MS = LoginHelper.AJGetWJItem(strRGJYBHGX);
                                }
                                else if (iSub > 15 && iSub < 22)
                                {
                                    manual.WGJC_PD = "2";
                                    strWGJC_MS = LoginHelper.AJGetWJItem(strRGJYBHGX);
                                }
                                else if (iSub > 21 && iSub < 42)
                                {
                                    manual.AQZZJY_PD = "2";
                                    strAQZZJY_MS = LoginHelper.AJGetWJItem(strRGJYBHGX);
                                }
                                else if (iSub == 80)
                                {
                                    manual.LWCX_PD = "2";
                                    strAQZZJY_MS = LoginHelper.AJGetWJItem(strRGJYBHGX);
                                }
                            }
                        }
                    }
                    manual.WYXRD_MS = strWYXRD_MS;
                    manual.CLTZCSJC_MS = strCLTZCSJC_MS;
                    manual.WGJC_MS = strWGJC_MS;
                    manual.AQZZJY_MS = strAQZZJY_MS;
                    manual.AQZZJY_MS = strAQZZJY_MS;
                }


      

                bool bSaveManual = false;
                if (manual_bll.Exists(manual.JCLSH))
                {
                    //bSaveManual = manual_bll.Update(manual, manual.JCLSH);
                }
                else
                {
                    //bSaveManual = manual_bll.Insert(manual);
                }

                if (bSaveManual == false)
                {
                    #region 日志记录
                    //LogHelper logHelper = LogHelper.GetSingleLogHelper();

                    //string strCategory = LogHelper.LogType.Error.ToString();
                    //LOG_INFO logInfo = new LOG_INFO();
                    //logInfo.Category = strCategory;
                    //logInfo.HostName = System.Net.Dns.GetHostName();
                    //logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                    //logInfo.LogTime = DateTime.Now;
                    //logInfo.Log_Infor = "保存外检人工项目失败，JCLSH：" + model_ZC.JCLSH + ", 号牌号码：" + model_ZC.HPHM;
                    //logInfo.OpName = userInfo.UserName;
                    //logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Normal);
                    //logInfo.FunName = "LoginAJ.aspx.cs -> btnSend_Click";

                    //logHelper.WriteLog(logInfo);
                    #endregion
                }
            }
            #endregion

            #region 联网18C66,更新数据
            Networking netWorking = Networking.Instance;
            if (netWorking.bSFLW && chkSFLW.Checked)
            {
                try
                {
                    Vehicle_18C66_Para m_18C66_Para = new Vehicle_18C66_Para();
                    m_18C66_Para.jylsh = model_ZC.AJLSH;
                    m_18C66_Para.jclsh = model_ZC.JCLSH;
                    m_18C66_Para.jyjgbh = netWorking.jyjgbh;
                    m_18C66_Para.jcxdh = Request["LineNum"].ToString();
                    m_18C66_Para.hphm = model_ZC.HPHM.Contains("试") ? string.Empty : model_ZC.HPHM;
                    m_18C66_Para.hpzl = (model_ZC.HPHM == string.Empty || model_ZC.HPHM.Contains("试")) ? string.Empty : model_ZC.HPZLDH;
                    m_18C66_Para.clsbdh = model_ZC.VIN;
                    m_18C66_Para.fdjh = info.FDJH;
                    m_18C66_Para.csys = "";
                    m_18C66_Para.syxz = info.SYXZDH;
                    m_18C66_Para.rlzl = info.RLLBDH;
                    if (string.IsNullOrEmpty(info.EDGL))
                    {
                        m_18C66_Para.gl = null;
                    }
                    else
                    {
                        m_18C66_Para.gl = Convert.ToInt32(info.EDGL);
                    }
                    if (string.IsNullOrEmpty(info.ZZS))
                    {
                        m_18C66_Para.zs = null;
                    }
                    else
                    {
                        m_18C66_Para.zs = Convert.ToInt32(info.ZZS);
                    }
                    if (string.IsNullOrEmpty(info.ZZL))
                    {
                        m_18C66_Para.zzl = null;
                    }
                    else
                    {
                        m_18C66_Para.zzl = Convert.ToInt32(info.ZZL);
                    }
                    if (string.IsNullOrEmpty(info.ZBZL))
                    {
                        m_18C66_Para.zbzl = null;
                    }
                    else
                    {
                        m_18C66_Para.zbzl = Convert.ToInt32(info.ZBZL);
                    }
                    if (string.IsNullOrEmpty(info.CCRQ))
                    {
                        m_18C66_Para.ccrq = null;
                    }
                    else
                    {
                        m_18C66_Para.ccrq = Convert.ToDateTime(info.CCRQ).ToString("yyyy-MM-dd");
                    }

                    if (string.IsNullOrEmpty(model_ZC.JYLBDH))
                    {
                        m_18C66_Para.jylb = model_ZC.JYLBDH;
                    }

                    if (!string.IsNullOrEmpty(info.QDZWZ))
                    {
                        m_18C66_Para.qdxs = info.QDZWZ;
                    }
                    if (string.IsNullOrEmpty(info.ZCZWZ))
                    {
                        m_18C66_Para.zczs = null;
                    }
                    else
                    {
                        string[] strZCZWZ = info.ZCZWZ.Split(',');
                        m_18C66_Para.zczs = strZCZWZ.Length - 1;

                        m_18C66_Para.zczw = info.ZCZWZ;
                    }
                    if (!string.IsNullOrEmpty(info.QZDZDH))
                    {
                        m_18C66_Para.qzdz = info.QZDZDH;
                    }
                    if (!string.IsNullOrEmpty(info.YGGSNFKTDH))
                    {
                        m_18C66_Para.ygddtz = info.YGGSNFKTDH;
                    }
                    if (!string.IsNullOrEmpty(info.ZXZXJXSDH))
                    {
                        m_18C66_Para.zxzxjxs = info.ZXZXJXSDH;
                    }
                    if (!string.IsNullOrEmpty(info.LJXSLC))
                    {
                        m_18C66_Para.lcbds = info.LJXSLC;
                    }
                    if (!string.IsNullOrEmpty(info.JYXM))
                    {
                        string strJYXM = LoginHelper.GetNetWorkJYXM(info.JYXM);

                        if (strJYXM.Substring(strJYXM.Length - 1, 1) == ",")
                        {
                            strJYXM = strJYXM.Substring(0, strJYXM.Length - 1);
                        }

                        m_18C66_Para.jyxm = strJYXM;
                    }
                    if (!string.IsNullOrEmpty(info.JYLBDH))
                    {
                        m_18C66_Para.jylb = info.JYLBDH.Substring(0, info.JYLBDH.Length - 1);
                    }
                    if (!string.IsNullOrEmpty(info.PP))
                    {
                        m_18C66_Para.clpp1 = info.PP;
                    }
                    if (!string.IsNullOrEmpty(info.XH))
                    {
                        m_18C66_Para.clxh = info.XH;
                    }
                    if (!string.IsNullOrEmpty(info.SYR))
                    {
                        m_18C66_Para.syr = info.SYR;
                    }
                    if (!string.IsNullOrEmpty(info.CLZLDH))
                    {
                        m_18C66_Para.cllx = info.CLZLDH;
                    }
                    m_18C66_Para.sjr = "";
                    m_18C66_Para.sjrsfzh = "";

                    AJ_ModelToXML modelToXml = new AJ_ModelToXML();
                    string strXML = modelToXml.ModelToXml("18C66", m_18C66_Para);


                    if (strXML.Contains("</jylsh>"))
                    {
                        strXML = strXML.Replace("</jylsh>", "</jylsh><jclsh>" + m_18C66_Para.jclsh + "</jclsh>");
                    }

                    IYASAKANetService.VehicleForIYASAKAService_AJSoapClient client = new IYASAKANetService.VehicleForIYASAKAService_AJSoapClient();
                    string strRetXML = client.writeObjectOut(netWorking.xtlb, netWorking.jkxlh, "18C66", strXML);

                    AJ_XMLToModel xmlToModel = new AJ_XMLToModel();
                    Vehicle_18C66_Result m_18C66_Result = (Vehicle_18C66_Result)xmlToModel.Result_XmlToModel("18C66", strRetXML);

                    if (m_18C66_Result.code == "0")
                    {
                        gfAjaxJs.SetAlertMsg(UpdatePanel1, "联网更新信息失败，失败原因为" + m_18C66_Result.message + "！");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    gfAjaxJs.SetAlertMsg(UpdatePanel1, "联网平台出错，出错信息为：18C66,更新数据出错！");
                    return;
                }
            }
            else
            {
                model_ZC.AJLSH = "";
            }
            #endregion

            bool bUpdateSuc = false;
            if (!bIsUpdate_ZC)
            {
                bUpdateSuc = disBll.Insert(model_ZC);
            }
            else
            {
                bUpdateSuc = disBll.Update(model_ZC, model_ZC.JCLSH);
            }

            if (bUpdateSuc)
            {
                #region 日志记录
                LogHelper logHelper = LogHelper.GetSingleLogHelper();

                string strCategory = LogHelper.LogType.Normal.ToString();
                LOG_INFO logInfo = new LOG_INFO();
                logInfo.Category = strCategory;
                logInfo.HostName = System.Net.Dns.GetHostName();
                logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                logInfo.LogTime = DateTime.Now;
                logInfo.Log_Infor = "发送成功，JCLSH：" + model_ZC.JCLSH + ", 号牌号码：" + model_ZC.HPHM;
                logInfo.OpName = userInfo.UserName;
                logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Normal);
                logInfo.FunName = "LoginAJ.aspx.cs -> btnSend_Click";

                logHelper.WriteLog(logInfo);
                #endregion

                gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送成功！");
                btnSend.CssClass = "btnSendEnabled";
                btnSend.Enabled = true;
                ResetAll();
                LoginedList1.BindList("", "");
                return;
            }
            else
            {
                #region 日志记录
                LogHelper logHelper = LogHelper.GetSingleLogHelper();

                string strCategory = LogHelper.LogType.Error.ToString();
                LOG_INFO logInfo = new LOG_INFO();
                logInfo.Category = strCategory;
                logInfo.HostName = System.Net.Dns.GetHostName();
                logInfo.IPAddress = logHelper.GetIPAddress(logInfo.HostName);
                logInfo.LogTime = DateTime.Now;
                logInfo.Log_Infor = "发送成功，JCLSH：" + model_ZC.JCLSH + ", 号牌号码：" + model_ZC.HPHM;
                logInfo.OpName = userInfo.UserName;
                logInfo.Name = logHelper.GetLogName(LogHelper.LogType.Error);
                logInfo.FunName = "LoginAJ.aspx.cs -> btnSend_Click";

                logHelper.WriteLog(logInfo);
                #endregion
                gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送失败！");
                btnSend.CssClass = "btnSendEnabled";
                btnSend.Enabled = true;
                return;
            }
        }


        private void ReBindJCXM()
        {
            //int iZZS = Convert.ToInt32(drpZZS.SelectedValue);
            int iQZDE = Convert.ToInt32(drpQZDZ.SelectedValue);

            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                foreach (var vItem in lstItems)
                {
                    if (chkJYXM.Items[i].Selected && chkJYXM.Items[i].Value == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }

            chkJYXM.Items.Clear();

            for (int i = 0; i < lstItems.Count; i++)
            {
                if (lstItems[i].Value.Substring(0, 1) == "B")
                {
                    
                }
                else if (lstItems[i].Value.Substring(0, 1) == "Z")
                {
                    
                }

                else if (lstItems[i].Value.Substring(0, 1) == "H")
                {
                    if (iQZDE == 2)
                    {
                        if (Convert.ToInt32(lstItems[i].Value.Substring(1, 1)) == 1 || Convert.ToInt32(lstItems[i].Value.Substring(1, 1)) == 4)
                        {
                            chkJYXM.Items.Add(lstItems[i]);
                        }
                    }
                    else
                    {
                        chkJYXM.Items.Add(lstItems[i]);
                    }
                }
                else
                {
                    chkJYXM.Items.Add(lstItems[i]);
                }
            }
        }


        protected void drpQZDZ_SelectedIndexChanged(object sender, EventArgs e)
        {
            ReBindJCXM();
        }

        protected void chkJYXM_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool bFirstTest = rbtnTest.SelectedValue == "0" ? true : false;

            bool bIsSLQC = drpCLZL.SelectedValue == "N11" ? true : false;
            LoginHelper.JYXMChanged(chkJYXM, lstItems, bFirstTest, bIsSLQC);
        }

 
        protected void btnFilter_Click(object sender, EventArgs e)
        {
            List<string> lstSelected = new List<string>();
            int iVehicleClass = 0;
            string strJYLB = drpTestType.SelectedValue;
            string strCLZL = drpCLZL.SelectedValue;
            string strSYXZ = drpSYXZ.SelectedValue;

            int iCYS = 0;
            if (!string.IsNullOrEmpty(txtHZRS.Text) && gfLibrary.gfValidate.Is_Integer(txtHZRS.Text))
            {
                iCYS = Convert.ToInt32(txtHZRS.Text);
            }

            bool IsOut10Year = false;
            if (!string.IsNullOrEmpty(txtCSDJRQ.Text) && gfValidate.Is_DateTime(txtCSDJRQ.Text))
            {
                IsOut10Year = Convert.ToDateTime(txtCSDJRQ.Text).AddYears(10) < DateTime.Now ? true : false;
            }

            //string strLW = drpLWCXWZJL.SelectedValue;

           // int iZZS = Convert.ToInt32(drpZZS.SelectedValue);

            //string strZXXJXS = drpZXZXJXS.SelectedValue;
           // string strZXZLX = drpZXZLX.SelectedValue;


            if (strCLZL == "N11")
            {// 三轮汽车
                iVehicleClass = 4;
            }
            else
            {
                if (strCLZL.Substring(0, 1) == "K")
                {// 客车
                    iVehicleClass = 1;
                    if (strSYXZ.Substring(0, 1) == "F")
                    {// 非营运
                        if (strCLZL.Substring(1, 1) == "3" || strCLZL.Substring(1, 1) == "4")
                        {// 非营运小型、微型载客汽车
                            iVehicleClass = 0;
                        }
                    }
                }
                else
                { // 载货汽车（三轮汽车除外）、专项作业车
                    iVehicleClass = 2;
                }
            }

            if (strCLZL.Substring(0, 1) == "H")
            {// ZL 2016-11-20 在用车检验时,仅对中、重型货车、挂车检测,见GB21861-2014 第6.3.1外廓尺寸
                if (strJYLB == "01" || strJYLB == "05")
                {
                    lstSelected.Add("M1"); //外廓尺寸
                }
                else if (strJYLB == "02")
                {
                    lstSelected.Add("W1");
                }
            }

            if (strJYLB == "01" || strJYLB == "05")
            {
                switch (iVehicleClass)
                {
                    case 0://非营运小型、微型载客汽车
                        
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }

                        if ((iCYS >= 7) || strCLZL == "K39" || strCLZL == "K49" || IsOut10Year)
                        {
                            lstSelected.Add("B0");// 驻车
                            lstSelected.Add("DC");// 动态底盘
                            lstSelected.Add("C1");// 底盘部件
                        }
                        // 联网查询有交通事故的，增加底盘 和动态底盘检验
                        
                        break;
                    case 1://其它类型载客汽车
                    case 2://载货汽车（三轮汽车除外）、专项作业车
                        lstSelected.Add("F1");// 外观
                        lstSelected.Add("S1");// 车速表

                        
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }
                        lstSelected.Add("B0");// 驻车
                        lstSelected.Add("DC");// 动态底盘
                        lstSelected.Add("C1");// 底盘部件


                        break;
                    case 4://三轮汽车
                        lstSelected.Add("F1");// 外观
                        lstSelected.Add("P9");// 外观
                      
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }
                        lstSelected.Add("DC");// 动态底盘
                        lstSelected.Add("C1");// 底盘部件
                        lstSelected.Add("P7");// 动态底盘
                        lstSelected.Add("P8");// 底盘部件
                        lstSelected.Add("P0");// 驻车制动
                        break;
                }
            }
            else if (strJYLB == "02")
            {
                lstSelected.Add("M1");
                lstSelected.Add("W1");

                switch (iVehicleClass)
                {
                    case 0://非营运小型、微型载客汽车
                        lstSelected.Add("F1");// 外观
                        lstSelected.Add("S1");// 
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }

                        if ((iCYS >= 7) || strCLZL == "K39" || strCLZL == "K49" || IsOut10Year)
                        {
                            lstSelected.Add("B0");// 驻车
                            lstSelected.Add("DC");// 动态底盘
                            lstSelected.Add("C1");// 底盘部件
                        }
                       
                        break;
                    case 1://其它类型载客汽车
                    case 2://载货汽车（三轮汽车除外）、专项作业车
                        lstSelected.Add("F1");// 外观
                        lstSelected.Add("S1");// 车速表
                        
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }
                        lstSelected.Add("B0");// 驻车
                        lstSelected.Add("DC");// 动态底盘
                        lstSelected.Add("C1");// 底盘部件
                        // 侧滑
                        
                        break;
                    case 4://三轮汽车
                        lstSelected.Add("P9");// 外观
                       
                        for (int i = 1; i < 5; i++)
                        {// 灯光
                            lstSelected.Add("H" + i);
                        }
                        lstSelected.Add("DC");// 动态底盘
                        lstSelected.Add("C1");// 底盘部件
                        lstSelected.Add("P7");// 动态底盘
                        lstSelected.Add("P8");// 底盘部件
                        lstSelected.Add("P0");// 驻车制动
                        break;
                }
            }

            lstItems.All(x => x.Selected = false);

            foreach (var vSelected in lstSelected)
            {
                foreach (var vItem in lstItems)
                {
                    if (vSelected == vItem.Value)
                    {
                        vItem.Selected = true;
                    }
                }
            }


            for (int i = 0; i < chkJYXM.Items.Count; i++)
            {
                chkJYXM.Items[i].Selected = false;
                foreach (var v in lstSelected)
                {
                    if (chkJYXM.Items[i].Value == v)
                    {
                        chkJYXM.Items[i].Selected = true;
                    }
                }
            }
        }


        protected void btnSearchPPXH_Click(object sender, EventArgs e)
        {
            string strPP = txtPP.Text.Trim();
            string strXH = txtXH.Text.Trim().ToUpper();
            TYPE_CX_CONTENT_BLL bll = new TYPE_CX_CONTENT_BLL();
            TYPE_CX_CONTENT[] m_TYPE_CX_CONTENT = bll.GetModelList("PP='" + strPP + "' and XH='" + strXH + "' order by ID desc");

            if (m_TYPE_CX_CONTENT.Length > 0)
            {
                TYPE_CX_CONTENT vContent = m_TYPE_CX_CONTENT[0];

                List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
                List<Control> lstControls = new List<Control>();

                lstCtl.Add(new LoginHelper.ControlNames(drpQZDZ.ID.ToString(), "QZDZ"));
                lstControls.Add(drpQZDZ);

                lstCtl.Add(new LoginHelper.ControlNames(drpRLLB.ID.ToString(), "RLLB"));
                lstControls.Add(drpRLLB);

                

                lstCtl.Add(new LoginHelper.ControlNames(drpCLZL.ID.ToString(), "CLZL"));
                lstControls.Add(drpCLZL);

                lstCtl.Add(new LoginHelper.ControlNames(txtHDZZL.ID.ToString(), "HDZH"));
                lstControls.Add(txtHDZZL);

                lstCtl.Add(new LoginHelper.ControlNames(txtHZRS.ID.ToString(), "CYS"));
                lstControls.Add(txtHZRS);

            

                lstCtl.Add(new LoginHelper.ControlNames(txtZBZL.ID.ToString(), "ZBZL"));
                lstControls.Add(txtZBZL);

             

                lstCtl.Add(new LoginHelper.ControlNames(txtZZL.ID.ToString(), "ZZL"));
                lstControls.Add(txtZZL);

                LoginHelper.GetPPXH(vContent, lstCtl, lstControls);

                drpQZDZ_SelectedIndexChanged(null, null);
            }
        }

        protected void lbtnCLZL_K_Click(object sender, EventArgs e)
        {
            //HPZL,CLZL,SYXZ,ZXZLX,ZXZXJXS,RYLL
            string[] strXX = new string[] { "01", "K11", "Y12", "1", "1", "B" };
            try
            {
                GetDefalutByCLLX(strXX);
            }
            catch (Exception ex)
            {

            }
        }

        protected void lbtnCLZL_H_Click(object sender, EventArgs e)
        {
            //HPZL,CLZL,SYXZ,ZXZLX,ZXZXJXS,RYLL
            string[] strXX = new string[] { "01", "H11", "Y18", "1", "1", "B" };
            try
            {
                GetDefalutByCLLX(strXX);
            }
            catch (Exception ex)
            {

            }

        }
   
        protected void lbtnCLZL_X_Click(object sender, EventArgs e)
        {
            //HPZL,CLZL,SYXZ,ZXZLX,ZXZXJXS,RYLL
            string[] strXX = new string[] { "02", "F01", "Y12", "1", "0", "A" };
            try
            {
                GetDefalutByCLLX(strXX);
            }
            catch (Exception ex)
            {

            }
        }

        private void GetDefalutByCLLX(string[] strLst)
        {
            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZL.ID, strLst[0]));
            lstControls.Add(drpHPZL);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZL.ID, strLst[1]));
            lstControls.Add(drpCLZL);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZ.ID, strLst[2]));
            lstControls.Add(drpSYXZ);

            lstCtl.Add(new LoginHelper.ControlNames(drpRLLB.ID, strLst[5]));
            lstControls.Add(drpRLLB);

            LoginHelper.ResetAllControls(lstCtl, lstControls);
        }

        protected void lbtnCLZL_Q_Click(object sender, EventArgs e)
        {
            //HPZL,CLZL,SYXZ,ZXZLX,ZXZXJXS,RYLL
            string[] strXX = new string[] { "02", "Q11", "Y18", "1", "1", "B" };
            try
            {
                GetDefalutByCLLX(strXX);
            }
            catch (Exception ex)
            {

            }
        }

        protected void rbtnTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoginHelper.BindTemplate("A", rbtnTemplate, chkJYXM, lstItems);
        }

        protected override void OnUnload(EventArgs e)
        {
            //UnSubscribe(cameraInfo);
            base.OnUnload(e);
        }

        public List<ListItem> lstItemsGC { get; set; }

    }
}